﻿using System.Text.Json.Serialization;

namespace Acme.MeiTuan.SDK.Response
{
    [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
    public class BaseResult
    {
        /// <summary>
        /// 
        /// </summary>
        public object? data { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int? result_code { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int? code { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Error? error { get; set; }

        public bool IsSuccess()
        {
            return data?.ToString() != "ng";
        }

        public bool IsRetry()
        {
            if (!IsSuccess())
            {
                if (code == 711 || error?.code == 711)
                    return true;
                if (code == 1021 || error?.code == 1021)
                    return true;
                if (error?.msg?.Contains("SYS_ERR") == true)
                    return true;
            }
            return false;
        }
    }

    [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
    public class Error
    {
        /// <summary>
        /// 
        /// </summary>
        public string? msg { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int? code { get; set; }
    }
}
